home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15725 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.7 KB

  1. Path: lrz-muenchen.de!news
  2. From: watzka@stat.uni-muenchen.de (Kurt Watzka)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: #include "" for large programs.
  5. Date: 21 Apr 1996 12:21:06 GMT
  6. Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
  7. Distribution: world
  8. Message-ID: <4ld97i$qtn@sparcserver.lrz-muenchen.de>
  9. References: <Pine.SUN.3.92.960411195730.24973A-100000@suntan> <4krrmi$7ef@mother.usf.edu> <4krurt$fat@sparcserver.lrz-muenchen.de> <317782EB.41C6@wight.hursley.ibm.com>
  10. NNTP-Posting-Host: sun2.lrz-muenchen.de
  11.  
  12. Max Waterman <dwater@wight.hursley.ibm.com> writes:
  13.  
  14. >Kurt Watzka wrote:
  15. >> 
  16. >> gohel@csee.usf.edu (Himanshu Gohel) writes:
  17. >> 
  18. >> >In article <Pine.SUN.3.92.960411195730.24973A-100000@suntan>, "Carlos Diaz (CS)" <cdiaz@eng.usf.edu> writes:
  19. >> 
  20. >> >The way to avoid multiple definitions (and similarly multiple inclusions
  21. >> >of .h files) is to do the following:
  22. >> 
  23. >> >#ifndef __MYHEADERFILE__
  24. >> >#define __MYHEADERFILE__
  25. >> > ...all your header file stuff here...
  26. >> >#endif
  27. >> 
  28. >> Change this to something not using macro names starting with a
  29. >> double underscore and an upper case letter and I will happily
  30. >> agree with you.
  31.  
  32. >Why not an uppercase letter? I user
  33. >#ifndef INCLUDED_MY_FUNCTION
  34. >#define INCLUDED_MY_FUNCTION
  35.  
  36.  
  37. "INCLUDED_MY_FUNCTION" does not start with a double underscore, much less
  38. with a double underscore _and_ an uppercase letter. Because I dislike 
  39. typing, I tend to use "INCL_MY_FUNCTION", but "INCLUDED_MY_FUNCTION" does
  40. not start with a double underscore, so ...
  41.  
  42. >> There also is a non zero chance that the stuff defined in the
  43. >> header file will be underfined in your compilation module that
  44. >> includes such a header.
  45.  
  46. >For type definitions, that is what the header file is for.
  47.  
  48. I was talking about the chance that the implementor of a system header
  49. file that is included before the header using "__MYHEADERFILE__" is
  50. included has defined "__MYHEADERFILE__", so that the contents of
  51. the header file will never be seen.
  52.  
  53. >> Try something like
  54. >> 
  55. >>    #if defined(GLOBALS)
  56. >>    #define GLOBAL
  57. >>    #else
  58. >>    #define GLOBAL extern
  59. >>    #endif
  60. >> 
  61. >>    GLOBAL const answer
  62. >>    #if defined(GLOBALS)
  63. >>      = 42;
  64. >>    #else
  65. >>      ;
  66. >>    #endif
  67. >> 
  68. >> Be sure to define "GLOBALS" in exactly one compilation unit that includes
  69. >> a header file with that construct.
  70.  
  71. >Don't see any point in GLOBAL - why not 'extern'.
  72.  
  73. There is no technical need for leaving out "global" in the actual definition,
  74. as long as there is an initialization in exactly one compilation unit. The
  75. main purpose for this construct is:
  76.  
  77.  a) An initialization is not needed for "GLOBAL" variables.
  78.  b) Documentation.
  79.  
  80. Kurt
  81. -- 
  82. | Kurt Watzka                             Phone : +49-89-2180-6254
  83. | watzka@stat.uni-muenchen.de
  84.